package com.example.leo.mycharmingstudent.a0911.launchmode;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.leo.mycharmingstudent.R;

public class SingleTopActivity extends BaseActivity {


    //启动standard模式Activity 按钮
    private Button btnStandard;
    //启动singleTop模式Activity 按钮
    private Button btnSingleTop;
    //启动singleTask模式Activity 按钮
    private Button btnSingleTask;
    //启动singleInstance模式Activity 按钮
    private Button btnSingleInstance;
    private Button btnBackResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_standard);

        findViews();
        initData();
        initEvent();
    }

    private void findViews() {
        btnStandard = findViewById(R.id.btn_start_standard_activity_standard);
        btnSingleTop = findViewById(R.id.btn_start_single_top_activity_standard);
        btnSingleTask = findViewById(R.id.btn_start_single_task_activity_standard);
        btnSingleInstance = findViewById(R.id.btn_start_single_instance_activity_standard);
        btnBackResult = findViewById(R.id.btn_back_result_activity_standard);
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                String name = bundle.getString("name");
                Log.e(getClass().getSimpleName(), "initData: " + name);
            }
        }

        Intent intent1 = new Intent();
        intent1.putExtra("info", "标准你好，已收到你的消息");
        setResult(RESULT_OK, intent1);
    }

    private void initEvent() {
        btnStandard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SingleTopActivity.this,
                        StandardActivity.class));
            }
        });
        btnSingleTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SingleTopActivity.this,
                        SingleTopActivity.class));
            }
        });
        btnSingleTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SingleTopActivity.this,
                        SingleTaskActivity.class));
            }
        });
        btnSingleInstance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SingleTopActivity.this,
                        SingleInstanceActivity.class));
            }
        });
        btnBackResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击按钮以后，设置数据，退出Activity
                Intent intent1 = new Intent();
                intent1.putExtra("info", "标准你好，已收到你的消息");
                setResult(RESULT_OK, intent1);
                finish();
            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
        /*
        注意，如果放到这里，需要先点击home键，再点击返回键才有效果
        直接点击返回键，没有效果
         */
        /*Intent intent1 = new Intent();
        intent1.putExtra("info", "标准你好，已收到你的消息");
        setResult(RESULT_OK, intent1);*/
    }
}
